# -*- coding: utf-8 -*-
"""
Created on Tue Dec 01 10:08:05 2015

@author: liliangrong
"""
# 知乎
import urllib
import urllib2

#setting header info
user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)' 
headers = {'User-Agent':user_agent}

#setting proxy
enable_proxy = True
proxy_handler = urllib2.ProxyHandler({"http":"http://some-proxy.com:8080"})
null_proxy_handler = urllib2.proxyHandler({})
if enable_proxy:
    opener = urllib2.build_opener(proxy_handler)
else:
    opener = urllib2.build_opener(null_proxy_handler)
urllib2.install_opener(opener)

#setting values
values = {"username":"liliangrong0@126.com","password":"llr139248","lt":"LT-460283-R93RdAVOheDdpFtw5NBz3mrlXn67Qu"}
data = urllib.urlencode(values)
url = "http://www.zhihu.com/question/123"

request = urllib2.Request(url,data,headers)
try:
    response = urllib2.urlopen(request,timeout=10)  #setting timeout
except urllib2.URLError,e:
    print e.reason
print response.read()